# encoding: utf-8
require 'json'

require File.expand_path('../models/Chatnamelist', File.dirname(__FILE__))
require File.expand_path('../models/ChatCont', File.dirname(__FILE__))
require File.expand_path('../models/Online', File.dirname(__FILE__))
class Msm < Controller
  def add
=begin    callback=@params[:callback]
    i=ChatCont.find_by(uid:@params[:uid])
    if i==nil then
    cont=ChatCont.new
    cont.uid=@params[:uid]
    cont.chatContent="聊天开始<br/>"
    cont.save
    end
    g=Chatnamelist.find_by(uid:@params[:uid])
    if g==nil then
    c=Chatnamelist.new
    c.uid=@params[:uid]
     if c.save
      callback+"(["+c.to_json+"])"
     else
      fie="fail"
      callback+"(["+ fie.to_json+"])"
     end
      end
=end
    callback=@params[:callback]
    user=@params[:user]
   c=Online.new
   c.chattext="您好,客服人员正在为您服务<br/><br/>"
    c.user=user
    c.save
   a=c.id

   callback+"([{cid:#{a}}])"
  end
  def addchat
     p=@params[:id]
     c=@params[:chattext]
     su=Online.find_by(id:p)
     su.chattext=su.chattext+c
     su.save
     s=Online.order(points: :desc).first
     a=s.points
     kkk=Online.find_by(id:p)
     kkk.points=a+1
     if kkk.ising=="yes" then
     else
     kkk.mas="new"
     end
     kkk.save



  end
  def serveraddchat
    p=@params[:id]
    c=@params[:chattext]
    su=Online.find_by(id:p)
    su.chattext=su.chattext+c
    su.save
  end
 def closenew
   p=@params[:id]
   op=@params[:oldid]
   ooo=Online.find_by(id:op)
   ooo.ising="no"
   ooo.save
   d=Online.find_by(id:p)
   d.mas="old"
   d.ising="yes"
   d.save
 end
   def show
     callback=@params[:callback]

     showlist=Online.order(points: :desc)
    callback+"("+showlist.to_json+")"

   end
  def chat
    #callback=@params[:callback]
    callback=@params[:callback]
    uid=@params[:id]
    u=Online.find_by(id:uid)

    callback+"(["+u.to_json+"])"
  end
  def zhiding
    s=Online.order(points: :desc).first
    a=s.points
    kkk=Online.find_by(id:4)
    kkk.points=a+1
    kkk.save

  end

  def del
    callback=@params[:callback]

    callback+"('asdasdasd')"
  end
  def check

    callback=@params[:callback]
    o=Online.find_by(mas:"new")
    if o==nil then

     callback+"('mms')"
    else

    callback+"('mmno')"
    end
  end
end